package com.modern.devtools.interfaces;

import com.modern.devtools.model.Server;

import java.util.Map;

/**
 * Interface for executing commands on remote or local systems.
 */
public interface CommandExecutor {
    
    /**
     * Executes a command on a specific server and returns the result
     * @param server The server to execute the command on
     * @param command The command to execute
     * @return ExecutionResult containing output, error, and exit code
     */
    ExecutionResult executeCommand(Server server, String command);
    
    /**
     * Executes a command with environment variables on a specific server
     * @param server The server to execute the command on
     * @param command The command to execute
     * @param environment Environment variables to pass to the command
     * @return ExecutionResult containing output, error, and exit code
     */
    ExecutionResult executeCommand(Server server, String command, Map<String, String> environment);
    
    /**
     * Uploads a file to the target server
     * @param server The server to upload to
     * @param localPath Path to the local file
     * @param remotePath Path where the file should be uploaded on the remote system
     */
    void uploadFile(Server server, String localPath, String remotePath);
    
    /**
     * Downloads a file from the target server
     * @param server The server to download from
     * @param remotePath Path to the remote file
     * @param localPath Path where the file should be downloaded locally
     */
    void downloadFile(Server server, String remotePath, String localPath);
    
    /**
     * Checks if the executor is connected to a specific server
     * @param server The server to check connection for
     * @return true if connected, false otherwise
     */
    boolean isConnected(Server server);
    
    /**
     * Connects to the specified server
     * @param server The server to connect to
     */
    void connect(Server server);
    
    /**
     * Disconnects from the specified server
     * @param server The server to disconnect from
     */
    void disconnect(Server server);
    
    /**
     * Result class for command execution
     */
    class ExecutionResult {
        private final String output;
        private final String error;
        private final int exitCode;
        
        public ExecutionResult(String output, String error, int exitCode) {
            this.output = output;
            this.error = error;
            this.exitCode = exitCode;
        }
        
        public String getOutput() {
            return output;
        }
        
        public String getError() {
            return error;
        }
        
        public int getExitCode() {
            return exitCode;
        }
        
        public boolean isSuccess() {
            return exitCode == 0;
        }
    }
}